

local SecondLevelMenuFirstRender = app.mvc.createListViewCell(...)

--data =
function SecondLevelMenuFirstRender.create()
    local sprite = SecondLevelMenuFirstRender.extend(cc.CSLoader:createNode(Res.HandBookFirstRender))
    if node == nil then
        ccui.Helper:doLayout(sprite)
    end
    sprite:init(data)
    return sprite
end

function SecondLevelMenuFirstRender:init(data)
    self.super.init(self, data)

    self:setContentSize(self._ui["Panel"]:getContentSize())
    self._ui["Panel/dot"]:setVisible(false)
    self._ui.selected_btn:setTouchEnabled(false)
    
    self._ui["Panel"]:addClickEventListener(function()
        if self._cellModel then
            self._cellModel:dispatchEvent("clickFirstRender", self._data)
        end
    end)
    self:refresh()
end


function SecondLevelMenuFirstRender:refresh()
    if self._data then
        local menuData = self._data.data
        local isHightLight = false
        local isExtend = false
        if self._cellModel then
            local shareData = self._cellModel:getShareData()
            if shareData then
                isHightLight = shareData.firstSelect == self._data.depthIndex
                isExtend = shareData.extends[self._data.depthIndex]
            end
        end

        if menuData.children and #menuData.children > 0 then
            self._ui.img_1:setVisible(isExtend)
            self._ui.img_2:setVisible(not isExtend)
        else
            self._ui.img_1:setVisible(false)
            self._ui.img_2:setVisible(false)
        end

        if isHightLight then
            self._ui.name:setTextColor(cc.c3b(255, 225, 132))
            self._ui.selected_btn:setBright(false)
        else
            self._ui.name:setTextColor(cc.c3b(109, 109, 109))
            self._ui.selected_btn:setBright(true)
        end

        self:setRedPoint(menuData.redPoint)
        self._ui.name:setString(menuData.name)
    end
end

function SecondLevelMenuFirstRender:setRedPoint(isShow)
    local panel = self._ui["Panel"]
    local flagNode = panel:getChildByName("_new_flag_node")

    if not isShow then
        if flagNode then
            flagNode:removeFromParent()
        end
    else
        if not flagNode then
            local posX, posY = self._ui["Panel/dot"]:getPosition()
            flagNode = cc.CSLoader:createNode(Res.NewFunctionFlagNode)
            flagNode:setName("_new_flag_node")
            panel:addChild(flagNode)
            flagNode:setPosition(cc.p(posX, posY))
        end
        flagNode:getTimeline():gotoFrameAndPlay( 0, flagNode:getTimeline():getDuration(), true )
    end
end

function SecondLevelMenuFirstRender:onCellsShareDataChange()
    self:refresh()
end


return SecondLevelMenuFirstRender
